package com.lxd.property.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lxd.property.pojo.User;
import com.lxd.property.service.UserService;

@Controller
@RequestMapping("user")
public class UserController {

	@Autowired
	private UserService userService;

	@RequestMapping(value = "addUser", method = RequestMethod.POST)
	@ResponseBody
	public boolean addUser(User user) {
		// System.out.println("loginName===" + user.getLoginName());
		// System.out.println("pwd===" + user.getPwd());
		// System.out.println("name===" + user.getName());
		int i = userService.addUser(user);
		return i == 1 ? true : false;
	}

	@RequestMapping(value = "findUser", method = RequestMethod.POST)
	@ResponseBody
	public boolean findUser(User user) {
		User user2 = userService.findUser(user);
		return user2 == null ? false : true;
	}

	@RequestMapping(value = "findAllUser", method = RequestMethod.POST)
	@ResponseBody
	public List<User> findAllUser() {
		return userService.findAllUser();
	}

	@RequestMapping(value = "delUserById", method = RequestMethod.POST)
	@ResponseBody
	public boolean delUserById(Integer id) {
		int i = userService.delUserById(id);
		return i == 1 ? true : false;
	}

	@RequestMapping(value = "findUserById", method = RequestMethod.POST)
	@ResponseBody
	public User findUserById(Integer id) {
		User user = userService.findUserById(id);
		System.out.println(user.getId());
		return user;

	}

	@RequestMapping(value = "updateInfo", method = RequestMethod.POST)
	@ResponseBody
	public boolean updateInfo(User user) {
		// System.out.println(user.getLoginName() + "" + user.getId());
		// System.out.println("123456");
		Integer i = userService.updateInfo(user);
		return i == 1 ? true : false;
	}
}
